package com.wiz.web.controllor;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.wiz.common.Constant;
import com.wiz.util.AddressUtil;

/**
 * 
 * @author xxy
 *
 */
@Controller
@RequestMapping("/Common")
public class CommonControllor {
	@RequestMapping(value="/downloadPhoto")
	public String downloadPhoto(HttpServletRequest request,HttpServletResponse response,
			@RequestParam(value = "url", required = false) String url,
			HttpSession session, Model model){
		FileInputStream fin = null;
		OutputStream os = null;
		try {
			fin = new FileInputStream(AddressUtil.defultAddress()+url);
			os = response.getOutputStream();
			byte[] b = new byte[2048];
			int length;
			while ((length = fin.read(b)) > 0) {
				os.write(b, 0, length);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				os.close();
				fin.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}
}
